<?php

namespace app\admin\controller;

use app\admin\model\Street;
use app\admin\service\OperationService;
use think\Request;

class Operation extends Backend
{
    /**
     * @var OperationService
     */
    protected $service;

    protected function initialize()
    {
        parent::initialize();
        $this->service = new OperationService();
    }

    public function getList(Request $request)
    {
        $data = $this->service->lists($request->param(), $this->userId);
        $this->jsonReturn($data);
    }

    public function info()
    {
        $no   = $this->request->param('no');
        $data = $this->service->info($no);
        $this->jsonReturn(['code' => 0, 'data' => $data]);
    }

    public function save(Request $request)
    {
        $param = $request->except(['create_user', 'create_time', 'update_user', 'update_time', 'verify_user']);
        $data = $this->service->save($param, $this->userId);
        $this->jsonReturn(['code' => 0, 'msg' => 'success', 'data' => $data]);
    }
    public function getstree(){
//        $param['longitude'] = '114.0464';
//        $param['latitude'] = '22.684943';
        $param = $this->request->post();
        $street             = (new Street)->getInfoByGrid($param['longitude'], $param['latitude'], ['id']);
        var_dump($street);
    }

    public function add(Request $request)
    {
        $param = $request->except(['create_user', 'create_time', 'update_user', 'update_time', 'verify_user']);
        $data = $this->service->add($param, $this->userId);
        $this->jsonReturn(['code' => 0, 'msg' => 'success', 'data' => $data]);
    }

    public function delete()
    {
        if ($this->request->has('id')) {
            $id = $this->request->param('id');
            $field = 'id';
        } else {
            $id = $this->request->param('no');
            $field = 'operation_no';
        }
        $this->service->delete($id, $field);
        $this->jsonReturn(message());
    }

    public function setShow(Request $request)
    {
        $this->service->setShow($request->param('no'));
        $this->jsonReturn(message());
    }

    public function getPushUser(Request $request)
    {
        $data = $this->service->getPushUser($request->param('id'));
        $this->jsonReturn(['code' => 0, 'msg' => 'success', 'data' => $data]);
    }

    public function pushMsg(Request $request)
    {
        $id = $request->param('id');
        $user = $request->param('user');
        $data = $this->service->pushMsg($id, $user);
        $this->jsonReturn(['code' => 0, 'msg' => 'success', 'data' => $data]);
    }
}
